1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # POS Membership module for OpenERP, Manage membership payments from POS.
5 # Copyright (C) 2013 L'Heureux Cyclage (<http://www.heureux-cyclage.org>)
7 # This file is a part of POS Membership
9 # POS Membership is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # ReMembership is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 ##############################################################################
23 from openerp
import netsvc
24 from openerp
.osv
import fields
, osv
25 from openerp
.tools
.translate
import _
27 class pos_order(osv
.osv
):
28 _inherit
= 'pos.order'
30 def _check_membership_product(self
, cr
, uid
, ids
, context
=None):
31 #TODO : check condition and return boolean accordingly
32 if not context
is None:
34 order_line_obj
= self
.pool
.get('pos.order.line')
35 data_order_line
= order_line_obj
.browse(cr
, uid
, ids
, context
=context
)
36 for data
in data_order_line
:
37 print("DEV: [pos_membership] [_check_membership_product] [order_line]: data=%s product=%s" % (str(data
.id), str(data
.product_id
))),
41 (_check_membership_product
, 'Error: Invalid Message', ['field_name']),
44 # XXX: copied from openerp/addons/point_of_sale/point_of_sale.py
45 def action_invoice(self
, cr
, uid
, ids
, context
=None):
46 print ("DEV: [pos_membership] [pos_order] [action_invoice]");
47 wf_service
= netsvc
.LocalService("workflow")
48 inv_ref
= self
.pool
.get('account.invoice')
49 inv_line_ref
= self
.pool
.get('account.invoice.line')
50 product_obj
= self
.pool
.get('product.product')
53 for order
in self
.pool
.get('pos.order').browse(cr
, uid
, ids
, context
=context
):
55 inv_ids
.append(order
.invoice_id
.id)
58 if not order
.partner_id
:
59 raise osv
.except_osv(_('Error!'), _('Please provide a partner for the sale.'))
61 acc
= order
.partner_id
.property_account_receivable
.id
62 # XXX: copied from openerp/addons/point_of_sale/point_of_sale.py to fix account.invoice.line creation
67 'journal_id': order
.sale_journal
.id or None,
68 'type': 'out_invoice',
69 'reference': order
.name
,
70 'partner_id': order
.partner_id
.id,
71 'comment': order
.note
or '',
72 'currency_id': order
.pricelist_id
.currency_id
.id, # considering partner's sale pricelist's currency
75 inv
.update(inv_ref
.onchange_partner_id(cr
, uid
, [], 'out_invoice', order
.partner_id
.id)['value'])
76 if not inv
.get('account_id', None):
77 inv
['account_id'] = acc
78 for line
in order
.lines
:
80 #'invoice_id': inv_id,
81 'product_id': line
.product_id
.id,
84 inv_name
= product_obj
.name_get(cr
, uid
, [line
.product_id
.id], context
=context
)[0][1]
85 inv_line
.update(inv_line_ref
.product_id_change(cr
, uid
, [],
87 line
.product_id
.uom_id
.id,
88 line
.qty
, partner_id
= order
.partner_id
.id,
89 fposition_id
=order
.partner_id
.property_account_position
.id)['value'])
90 if line
.product_id
.description_sale
:
91 inv_line
['note'] = line
.product_id
.description_sale
92 inv_line
['price_unit'] = line
.price_unit
93 inv_line
['discount'] = line
.discount
94 inv_line
['name'] = inv_name
95 inv_line
['invoice_line_tax_id'] = ('invoice_line_tax_id' in inv_line
)\
96 and [(6, 0, inv_line
['invoice_line_tax_id'])] or []
97 #inv_line_ref.create(cr, uid, inv_line, context=context)
98 inv
['invoice_line'].append((0, 0, inv_line
))
99 inv_id
= inv_ref
.create(cr
, uid
, inv
, context
=context
)
101 self
.write(cr
, uid
, [order
.id], {'invoice_id': inv_id
, 'state': 'invoiced'}, context
=context
)
102 inv_ref
.confirm_paid(cr
, uid
, [inv_id
], context
=context
)
103 inv_ids
.append(inv_id
)
104 inv_ref
.button_reset_taxes(cr
, uid
, [inv_id
], context
=context
)
105 wf_service
.trg_validate(uid
, 'pos.order', order
.id, 'invoice', cr
)
107 if not inv_ids
: return {}
109 mod_obj
= self
.pool
.get('ir.model.data')
110 res
= mod_obj
.get_object_reference(cr
, uid
, 'account', 'invoice_form')
111 res_id
= res
and res
[1] or False
113 'name': _('Customer Invoice'),
117 'res_model': 'account.invoice',
118 'context': "{'type':'out_invoice'}",
119 'type': 'ir.actions.act_window',
122 'res_id': inv_ids
and inv_ids
[0] or False,
127 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: